import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  // 动画页面
  { path: '/action', component: () => import('@/views/Films/Action') },
  //首页-文章列表
  {
    path: '/home',
    // which is lazy-loaded when the route is visited.
    component: () => import('@/views/Films/Home.vue'),
    children: [
      {
        path: 'in_theaters',
        component: () => import('@/views/Films/Childs/InTheaters.vue'),
      },
      //留言板页面
      {
        path: 'comment',
        component: () => import('@/views/Films/Childs/ComingSoon.vue'),
      },
    ],
  },
  // 详情页
  {
    path: '/detail/:id',
    name: 'detail',
    component: () => import('@/views/Films/Detail.vue'),
  },
  // 关于团队页面
  {
    path: '/team',
    component: () => import('@/views/Films/Childs/AboutTeam.vue'),
  },
  // 分类文章详情页
  {
    path: '/cadetail/:id',
    name: 'cadetail',
    component: () => import('@/views/Films/Childs/CategoryView'),
  },
  // 重定向到首页
  {
    path: '/',
    redirect: '/action',
  },
  //404
  {
    path: '*',
    component: () => import('@/views/NotFound/404.vue'),
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  // keepalive与生命周期--保存返回时的位置在页面最上面
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { y: 0 }
    }
  },
})

export default router
